<?php

#This will load the first Race into the Database Race table
#ready for the start of betting
#there should be no need to alter this page in any way

  
 
$name_es = sqlite_escape_string($name);



   $db = sqlite_open('horse.db', 0666, $error);
      
#Read Data from race1
# set horse numbers and Names
$hn =1 ;
$result = sqlite_array_query($db, "SELECT * FROM race1", SQLITE_ASSOC);
foreach ($result as $entry) {
  #echo 'Horse: ' . $entry['horse_num'] .' ' . $entry['horse_name'].' :- '.'number of bets : '. $entry['bets'] .':- '.' Payout :'. $entry['payout'].'<br>';
  $Hname = $entry['horse_name'];
   #if (!$dbhandle) die ($error);
  #write this into the current race database  
   $stm = "UPDATE race SET horse_name ='$Hname' WHERE horse_num = '$hn'";
   $ok = sqlite_query($db, $stm, $error);
    #echo $stm;
   if (!$ok) die("Error: $error");  
 
   #increase hn to chnage horse names
   $hn++;
   #echo $hn;
}
sqlite_query($db, "UPDATE race SET payout ='0'",$sqliteerror);
sqlite_query($db, "UPDATE race SET bets ='0'",$sqliteerror);
sqlite_query($db, "UPDATE race SET decimal_odds ='0' WHERE horse_num = '9'",$sqliteerror);
sqlite_query($db, "UPDATE race SET bets ='1' WHERE horse_num = '9'",$sqliteerror);
sqlite_close($db);
echo <<<endHTML
<html>
<head><title>Race 1 </title></head>
<body>

<center>
race 1 has been entered into the system  <br>
ALL charity money has been cleared

Please procede to the tote page

<a href="tote.php"> click here</a>
endHTML;
?>